// 菜单管理路由
import { Router } from 'express';
import menuController from '@/controllers/system/menu.controller';
import { authMiddleware } from '@/middlewares/auth.middleware';
import { permissionMiddleware } from '@/middlewares/permission.middleware';
import { createController } from '@/utils/router/route.controller';
import { validateMenuCreate, validateMenuUpdate, validateMenuRemove } from '@/validators/system/menu.validator';

const router = createController(Router());

/**
 * 菜单管理路由
 * 路径前缀：/system/menu
 */

// 所有路由均需认证
router.use(authMiddleware);

// ================== 菜单相关 ==================
// 获取菜单列表
router.get('/list', permissionMiddleware('system:menu:list'), menuController.list);

// 获取菜单树形结构
router.get('/treeselect', permissionMiddleware('system:menu:list'), menuController.treeselect);

// 获取用户菜单树
router.get('/userMenuTree', permissionMiddleware('system:menu:list'), menuController.userMenuTree);

// 获取路由信息
router.get('/getRouters', permissionMiddleware('system:menu:list'), menuController.getRouters);

// 获取用户权限标识
router.get('/getPermissions', permissionMiddleware('system:menu:list'), menuController.getPermissions);

// 根据角色ID查询菜单树
router.get('/roleMenuTreeselect/:roleId', permissionMiddleware('system:menu:list'), menuController.roleMenuTreeselect);

// 获取菜单详细信息
router.get('/:menuId', permissionMiddleware('system:menu:query'), menuController.getInfo);

// ================== 新增、修改、删除 ==================
// 新增菜单
router.POST('', permissionMiddleware('system:menu:add'), validateMenuCreate, menuController.add);

// 修改菜单
router.PUT('', permissionMiddleware('system:menu:edit'), validateMenuUpdate, menuController.update);

// 删除菜单
router.DELETE('/:menuId', permissionMiddleware('system:menu:remove'), validateMenuRemove, menuController.remove);

export default router;